

package com.hexinfo.dmpro.sparing.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.sparing.dto.BackupLibraryDTO;
import com.hexinfo.dmpro.sparing.model.HotStandbyLogSource;
import com.hexinfo.dmpro.sparing.model.SyncCompleteLibrary;
import com.hexinfo.dmpro.sparing.service.LibraryLevelRetryService;
import org.springframework.http.ResponseEntity;
import com.hexinfo.dmpro.sparing.model.SyncCompleteLibraryTask;
import com.hexinfo.dmpro.sparing.service.SyncCompleteLibraryTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 热备全库日志任务表
 *
 * @author yemw
 * @date 2023-11-30 11:06:35
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/synccompletelibrarytask" )
@Api(value = "synccompletelibrarytask", tags = "热备全库日志任务表管理")
public class SyncCompleteLibraryTaskController {

    private final  SyncCompleteLibraryTaskService syncCompleteLibraryTaskService;

    private final LibraryLevelRetryService libraryLevelRetryService;
    /**
     * 分页查询
     * @param page 分页对象
     * @param syncCompleteLibraryTask 热备全库日志任务表
     * WrapperEnhancer.like(syncCompleteLibraryTask); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @AnonymousAccess
    public ResponseEntity<Object> getSyncCompleteLibraryTaskPage(Page page, SyncCompleteLibraryTask syncCompleteLibraryTask) {
        return ResponseEntity.ok(syncCompleteLibraryTaskService.queryList(page,syncCompleteLibraryTask));
    }


    @ApiOperation(value = "首页统计-库级热备", notes = "首页统计-库级热备")
    @GetMapping("/hotBackupLibraryTotal" )
//    @AnonymousAccess
    public ResponseEntity<Object> hotBackupLibraryTotal(BackupLibraryDTO backupLibraryDTO) {
        return ResponseEntity.ok(syncCompleteLibraryTaskService.hotBackupLibraryTotal(backupLibraryDTO));
    }

    @ApiOperation(value = "首页统计-库级表级热备", notes = "首页统计-库级表级热备")
    @GetMapping("/hotBackupLibraryTableTotal" )
//    @AnonymousAccess
    public ResponseEntity<Object> hotBackupLibraryTableTotal(BackupLibraryDTO backupLibraryDTO) {
        return ResponseEntity.ok(syncCompleteLibraryTaskService.hotBackupLibraryTableTotal(backupLibraryDTO));
    }

    /**
     * 通过id查询热备全库日志任务表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(syncCompleteLibraryTaskService.getById(id));
    }

    /**
     * 新增热备全库日志任务表
     * @param syncCompleteLibraryTask 热备全库日志任务表
     * @return R
     */
    @ApiOperation(value = "新增热备全库日志任务表", notes = "新增热备全库日志任务表")
    @PostMapping
    public ResponseEntity<Object> save(@RequestBody SyncCompleteLibraryTask syncCompleteLibraryTask) {
        return ResponseEntity.ok(syncCompleteLibraryTaskService.save(syncCompleteLibraryTask));
    }

    /**
     * 修改热备全库日志任务表
     * @param syncCompleteLibraryTask 热备全库日志任务表
     * @return R
     */
    @ApiOperation(value = "修改热备全库日志任务表", notes = "修改热备全库日志任务表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody SyncCompleteLibraryTask syncCompleteLibraryTask) {
        return ResponseEntity.ok(syncCompleteLibraryTaskService.updateById(syncCompleteLibraryTask));
    }

    /**
     * 通过id删除热备全库日志任务表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除热备全库日志任务表", notes = "通过id删除热备全库日志任务表")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(syncCompleteLibraryTaskService.removeById(id));
    }

    @ApiOperation(value = "库级重试", notes = "库级重试")
    @PostMapping("/levelRetry" )
    @AnonymousAccess
    public ResponseEntity<Object> levelRetry(@RequestBody List<SyncCompleteLibrary> list) {
        return ResponseEntity.ok(libraryLevelRetryService.levelRetry(list));
    }

    @ApiOperation(value = "库级重试(建表)", notes = "库级重试(建表)")
    @PostMapping("/levelRetryCreateTable" )
    @AnonymousAccess
    public ResponseEntity<Object> levelRetryCreateTable(@RequestBody SyncCompleteLibrary library) {
        return ResponseEntity.ok(libraryLevelRetryService.levelRetryCreateTable(library));
    }

    @ApiOperation(value = "库级重试(DISTCP，刷表)", notes = "库级重试(DISTCP，刷表)")
    @PostMapping("/levelRetryDistcp" )
    @AnonymousAccess
    public ResponseEntity<Object> levelRetryDistcp(@RequestBody SyncCompleteLibrary library) {
        return ResponseEntity.ok(libraryLevelRetryService.levelRetryDistcp(library));
    }

    @ApiOperation(value = "库级重试(稽核)", notes = "库级重试(稽核)")
    @PostMapping("/levelRetryAudit" )
    @AnonymousAccess
    public ResponseEntity<Object> levelRetryAudit(@RequestBody SyncCompleteLibrary library) {
        return ResponseEntity.ok(libraryLevelRetryService.levelRetryAudit(library));
    }
}
